﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using VideoClub.EN.classes;

namespace VideoClub.DS.classes.sp
{
   public class Sp_Mod_Handler
    {
        public int modActor(Actor actor, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_actor", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidactor", SqlDbType.Int).Value = actor.Idactor;
                    cmd.Parameters.Add("@pnomactor", System.Data.SqlDbType.VarChar, 50).Value = actor.Nomactor;
                    cmd.Parameters.Add("@papactor", SqlDbType.VarChar, 50).Value = actor.Apactor;
                    cmd.Parameters.Add("@pnacionactor", SqlDbType.Int).Value = actor.Nacionactor;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modCategoriaPeli(CategoriaPelicula categoriapelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_add_categoriapeli", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidcategoriapeli", SqlDbType.Int).Value = categoriapelicula.Idcategoriapelicula;
                    cmd.Parameters.Add("@pnombrecategoria", SqlDbType.VarChar, 50).Value = categoriapelicula.Nombrecategoria;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modNacionalidad(Nacionalidad nacionalidad, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_nacionalidad", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidnacionalidad", SqlDbType.Int).Value = nacionalidad.idnacionalidad;
                    cmd.Parameters.Add("@pnombre", SqlDbType.VarChar, 50).Value = nacionalidad.nombrenacionalidad;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modPelicula(Pelicula pelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_pelicula", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidpelicula", SqlDbType.Int).Value = pelicula.Idpelicula;
                    cmd.Parameters.Add("@pnompelicula", SqlDbType.VarChar, 50).Value = pelicula.Nompelicula;
                    cmd.Parameters.Add("@pestrenopeli", SqlDbType.DateTime).Value = pelicula.Estrenopeli;
                    cmd.Parameters.Add("@psipnosis", SqlDbType.VarChar, 1000).Value = pelicula.Sipnosis;
                    cmd.Parameters.Add("@ptrailerlink", SqlDbType.VarChar, 200).Value = pelicula.Trailerlink;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modPeliImgFile(PeliImageFile peliimgfile, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_peliimgfile", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidpelicula", SqlDbType.Int).Value = peliimgfile.Idpelicula;
                    cmd.Parameters.Add("@pfilename", SqlDbType.VarChar, 100).Value = peliimgfile.Filename;
                    cmd.Parameters.Add("@pfilepath", SqlDbType.VarChar, 100).Value = peliimgfile.Filepath;
                    cmd.Parameters.Add("@pfileprefix", SqlDbType.VarChar, 100).Value = peliimgfile.Fileprefix;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modSolicitud(Solicitud solicitud, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_solicitud", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidsolicitud", SqlDbType.Int).Value = solicitud.Idsolicitud;
                    cmd.Parameters.Add("@pfechasolicitud", SqlDbType.DateTime).Value = solicitud.Fechasolicitud;
                    cmd.Parameters.Add("@pidusuario", SqlDbType.Int).Value = solicitud.Idusuario;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modTipoUsuario(TipoUsuario tipousuario, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_tipousuario", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pnombretipousuario", SqlDbType.VarChar, 50).Value = tipousuario.Nombretipousuario;
                    cmd.Parameters.Add("@pidtipousuario", SqlDbType.Int).Value = tipousuario.Tipousuario;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modUsuario(Usuario usuario, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_usuario", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidusuario", SqlDbType.Int).Value = usuario.Idusuario;
                    cmd.Parameters.Add("@pcorreouser", SqlDbType.VarChar, 100).Value = usuario.Correouser;
                    cmd.Parameters.Add("@ptelfuser", SqlDbType.VarChar, 50).Value = usuario.Telfuser;
                    cmd.Parameters.Add("@pnombreuser", SqlDbType.VarChar, 50).Value = usuario.Nombreuser;
                    cmd.Parameters.Add("@pclave", SqlDbType.VarChar, 50).Value = usuario.Clave;
                    cmd.Parameters.Add("@papellidouser", SqlDbType.VarChar, 50).Value = usuario.Apellidouser;
                    cmd.Parameters.Add("@pnacionuser", SqlDbType.Int).Value = usuario.Nacionuser;
                    cmd.Parameters.Add("@ptipouser", SqlDbType.Int).Value = usuario.Tipuser;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }

        public int modvideoPelicula(VideoPelicula videopelicula, ref string log)
        {
            try
            {
                int rowsaffected = 0;
                using (var conec = new SqlConnection(Properties.Settings.Default.Chesco_PC_Connection_String))
                {
                    SqlCommand cmd = new SqlCommand("Sp_mod_videopelicula", conec);
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Parameters.Add("@pidvideopelicula", SqlDbType.Int).Value = videopelicula.Idpelicula;
                    cmd.Parameters.Add("@ppreciopel", SqlDbType.Money).Value = videopelicula.Preciovideopelicula;
                    cmd.Parameters.Add("@pestadovideo", SqlDbType.Int).Value = videopelicula.Estadovideopelicula;
                    conec.Open();
                    rowsaffected = cmd.ExecuteNonQuery();
                    log += rowsaffected;
                    return rowsaffected;
                }
            }
            catch (Exception ex)
            {
                log += ex.Message + ex.StackTrace + ex.Source;
                throw ex;
            }
        }
    }
}
